﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace QbservableCore.Serialization
{
    static internal class Lambda
    {
        public static void ToJson<T>(Expression<T> node, ExpressionToJson state)
        {
            string bodyPropName = state.Convention.FromKeyToConvention(Consts.Json.Body);
            string returnPropName = state.Convention.FromKeyToConvention(Consts.Json.Return);

            state.JsonCurrent.AddProperty(Consts.Json.Category, node.NodeType, state);
            // TODO: check if it is ok to send JArray
            JContainer body = state.CreateAndTransform(node.Body, new JArray());
            state.JsonCurrent.AddParamsToJson(node.Parameters, state);
            state.JsonCurrent.AddPropertyRaw(Consts.Json.Body, body, state);
            state.JsonCurrent.AddProperty(node.ReturnType, state, Consts.Json.Return);
        }
    }
}
